home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / cenvid.zip / GETUKEY.CMM < prev    next >
Text File  |  1993-04-06  |  2KB  |  40 lines

  1. // GetUKey.cmm    Cmm source code, used with CEnvi from the command line or
  2. //                from a batch file, to display a prompt and then set
  3. //                the UKEY environment variable to the key character pressed.
  4.  
  5. main(argc,argv)
  6. {
  7.    if (argc < 2) {
  8.       // no arguments were given, and so show how to use
  9.       Instructions();
  10.    } else {
  11.       // everything up to the last argument is the prompt
  12.       for ( KeyArg = 1; KeyArg < (argc-1); KeyArg++ )
  13.          printf("%s ",argv[KeyArg])
  14.       KeyList = strupr(argv[KeyArg])
  15.       // flush keyboard
  16.       while kbhit() getch();
  17.       // read until one of the keys from KeyList is pressed
  18.       while ( 0==(key=toupper(getch()))  ||  NULL == strchr(KeyList,key) )
  19.          printf("\a")   // beep because an invalid key was pressed
  20.       printf("%c\n",key)
  21.       // save this key as short environment string UKEY
  22.       (UKEY = "*")[0] = key
  23.    }
  24. }
  25.  
  26. Instructions()
  27. {
  28.    printf("\a\n")
  29.    printf("GetUKey.cmm - Display a prompt and get key from user input.  The\n")
  30.    printf("              environment variable UKEY will be set to the key selected\n")
  31.    printf("\n")
  32.    printf("USAGE: CEnvi GetUKey.cmm [Prompt] <KeyList>\n")
  33.    printf("Where:\n")
  34.    printf("   Prompt  - Text to display before prompting for character\n")
  35.    printf("   KeyList - A string with the characters that will be accepted\n")
  36.    printf("\n")
  37.    printf("Example: CEnvi GetUKey.cmm \"Copy File, Delete it, or Quit? (C/D/Q)\" CDQ\n")
  38. }
  39.  
  40.